//
//  main.cpp
//  Practice11
//
//  Created by 赵世杰 on 2020/7/25.
//  Copyright © 2020 zhaoshijie. All rights reserved.
//

#include <iostream>
#include<cstdlib>
#include<ctime>
#include"VectorClass.hpp"
#include"VectorClass2.hpp"
#include<fstream>
#include "TimeClass.hpp"
#include "StonewtClass.hpp"
#include "Complex0.hpp"


using namespace std;


int main(int argc, const char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";
    
    
    
    /*
    
    // 1、
    
    ofstream outFile;
    outFile.open("carinfo.txt");
    using VECTOR::Vector;
    srand(time(0));
    double direction;
    Vector result(0.0, 0.0);
    Vector step;
    unsigned long steps = 0;
    double target;
    double dstep;
    cout << "Enter target distance (q to quit): ";
    while (cin >> target)
    {
        cout << "Enter step length: ";
        if (!(cin >> dstep))
            break;
        outFile << "Target Distance:" <<target<<", Step Size: "<<dstep << endl;
        while (result.magval() < target)
        {
            direction = rand() % 360;
            step.reset(dstep, direction, Vector::POL);
            result = result + step;
            steps++;
            cout << steps << ": (x,y) = (" << result.xval() << "," << result.yval() <<")"<< endl;
            outFile << steps << ": (x,y) = (" << result.xval() << "," << result.yval() << ")" << endl;
        }

        //output the screen
        cout << "After " << steps << " steps ,the subject "
            "has the following locaion\n";
        cout << result << endl;
        //output the file
        outFile << "After " << steps << " steps ,the subject "
            "has the following locaion\n";
        outFile << result << endl;

        result.polar_mode();
        //output the screen
        cout << " or\n" << result << endl;
        cout << " Average outward distance per step = "
            << result.magval() / steps << endl;
        //output the file
        outFile << " or\n" << result << endl;
        outFile << " Average outward distance per step = "
            << result.magval() / steps << endl;

        steps = 0;
        result.reset(0.0, 0.0);
        cout << "Enter target distance (q to quit): ";

    }
    cout << "Bye!\n";
    cin.clear();
    while (cin.get() != '\n')
        continue;

    outFile.close();
    
    */
    
    
    /*
    // 2、
    

    using VECTOR2::Vector2;
    srand(time(0));
    double direction;
    Vector2 result(0.0, 0.0);
    Vector2 step;
    unsigned long steps = 0;
    double target;
    double dstep;
    cout << "Enter target distance (q to quit): ";
    while (cin >> target)
    {
        cout << "Enter step length: ";
        if (!(cin >> dstep))
            break;
        while (result.magval() < target)
        {
            direction = rand() % 360;
            step.reset(dstep, direction, Vector2::POL);
            result = result + step;
            steps++;
            cout << steps << ": (x,y) = (" << result.xval() << "," << result.yval() <<")"<< endl;
        }

        //output the screen
        cout << "After " << steps << " steps ,the subject "
            "has the following locaion\n";
        cout << result << endl;
        //output the file

        result.polar_mode();
        //output the screen
        cout << " or\n" << result << endl;
        cout << " Average outward distance per step = "
            << result.magval() / steps << endl;
        //output the file

        steps = 0;
        result.reset(0.0, 0.0);
        cout << "Enter target distance (q to quit): ";

    }
    cout << "Bye!\n";
    cin.clear();
    while (cin.get() != '\n')
        continue;
    */
    
    
    /*
    
    // 3、
    
    using VECTOR::Vector;
    srand(time(0));
    double direction;
    Vector step;
    Vector result(0.0, 0.0);
    unsigned long steps = 0;
    double target;
    double dstep;
    int N;
    int maxsteps, minsteps, sumsteps;
    maxsteps = 0;
    minsteps = 65535;
    sumsteps = 0;
    double avesteps;
    cout << "How many times of test would you want: ";
    cin >> N;
    cout << "\nEnter target distance: ";
    cin >> target;
    cout << "Enetr step length: ";
    cin >> dstep;
    cout << endl;
    for (int i = 0; i < N; i++)
    {
        while (result.magval() < target)
        {
            direction = rand() % 360;
            step.reset(dstep, direction, Vector::POL);
            result = result + step;
            steps++;
        }
        sumsteps += steps;
        if (steps > maxsteps)
        {
            maxsteps = steps;
        }
        if (steps < minsteps)
        {
            minsteps = steps;
        }
        steps = 0;
        result.reset(0.0, 0.0);
    }
    avesteps = sumsteps / N;
    cout << "Walk finished!\nAfter " << N << " times of test, the result is following:\n";
    cout << "The maxmum steps is " << maxsteps << ", the minimum steps is " << minsteps << ", and the average steps is " << avesteps << ".\n";
    cout << "Bye!\n";
    cin.clear();
    while (cin.get() != '\n')
        continue;
     
     */
    
    
    /*
    
    // 4、
    
    Time aida(3,35);
    Time tosca(2,48);
    Time temp;
    
    cout << "Aida and Tosca:\n";
    cout << aida << ";" << tosca << endl;
    temp = aida + tosca;
    cout << "Aida + Tosca: " << temp << endl;
    temp = aida * 1.17;
    cout << "Aida * 1.17: " << temp << endl;
    cout << "10.0 * Tosca: " << 10.0 * tosca << endl;
    
    */
    
    
    /*
    
    // 5、
    
    Stonewt incognito = 275;
    Stonewt wolfe(285.7);
    Stonewt taft(21,8);
    cout << "The celebrity weighed ";
    incognito.show_stn();
    cout << "The detetive weighed ";
    wolfe.show_stn();
    cout << "The President weighed ";
    taft.show_lbs();
    incognito = 276.8;
    taft = 325;
    cout << "After dinner, the celebrity weighed ";
    incognito.show_stn();
    cout << "After dinner, the President weighed ";
    taft.show_lbs();
    
    wolfe.show_lbs();
    taft.show_lbs();
    
    (wolfe+taft).show_lbs();
    (taft-wolfe).show_lbs();
    
    (wolfe*2).show_lbs();
    (2*wolfe).show_lbs();
    
    cout << (wolfe*2);
    
    */
    
    
    /*
    
    // 6、
    
    Stonewt stonewt0 = 275;
    Stonewt stonewt1(285.7);
    Stonewt stonewt2(21,8);
    
    Stonewt ston[6];
    ston[0] = stonewt0;
    ston[1] = stonewt1;
    ston[2] = stonewt2;
    
    for (int i=0; i<3; i++) {
        
        cout << "请输入数据 " << i + 3 << ":";
        
        float value ;
        
        cin >> value;
        cout << endl;
        
        Stonewt stonewt = value;
        
        ston[i+3] = stonewt;
        
    }
    
    Stonewt minSton = ston[0] ;
    Stonewt maxSton = ston[0] ;
    
    for (int i=1;i<sizeof(ston)/sizeof(ston[0]) - 1; i++)
    {
        if(minSton>ston[i])
        {
            minSton = ston[i];
        }
        
        if(ston[i]>maxSton)
        {
            maxSton = ston[i];
        }
        
    }
    
    
    cout << "所有英石：" << endl;
    for (int i=0;i<sizeof(ston)/sizeof(ston[0]); i++)
    {
        cout <<  ston[i];
        
    }
    
    
    
    cout << "max:\n";
    cout << maxSton << endl;
    
    
    cout << "min:\n";
    cout << minSton;
    
    
    Stonewt def(11,0);
    
    for (int i=0;i<sizeof(ston)/sizeof(ston[0]); i++)
    {
        if(ston[i]>def)
        {
            cout << "大于11英石：" << endl;
            cout <<  ston[i];
        }
        
    }
     
     */
    
    
    // 7、
    
    Complex0 a(3.0,4.0);
    
    Complex0 c;
    
    cout << "Enter a complex number (q to quit):\n";
    
    while (cin >> c) {

        cout << "a is" << a << "\n";
        cout << "a + c is" << a+c << "\n";
        cout << "a - c is" << a-c << "\n";
        cout << "a * c is" << a*c << "\n";
        cout << "2 * c is" << 2*c << "\n";
        
        cout << "Enter a complex number (q to quit):\n";
        
        
    }
    
    cout << "Done!\n";
    
    return 0;
}


void display(const Stonewt & st , int n)
{
    for (int i = 0; i<n; i++)
    {
        cout << "Wow! ";
        st.show_stn();
        
    }
}

